<?php

declare (strict_types=1);
/**
 * 创建人 : Forpastime
 *
 * @link     http://hypercmf.com
 * @document https://hyperf.wiki
 * @contact  forpastime@qq.com
 * @git  https://gitee.com/hypercmf/hypercmf1.0.git
 */
namespace App\Model;

/**
 * @property int $id 
 * @property string $video_id 
 * @property int $category_id 
 * @property string $title 
 * @property string $stream_infos 
 * @property string $m3u8 
 * @property string $path 
 * @property string $cover 
 * @property int $create_time 
 * @property string $status 
 * @property string $upload_status 
 * @property string $desc 
 * @property string $file_hash
 * @property int $quality 
 */
class Aliyunvod extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'aliyunvod';

    public $timestamps = false;
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'category_id' => 'integer', 'create_time' => 'integer', 'quality' => 'integer'];

    public function getList($where = [], $field=[], $limit=10)
    {
        $res =  $this->where($where)->select($field)->orderByDesc('updated_at')->orderByDesc('id')->paginate(intval($limit));
        if(!empty($res)){
            return for_paginator_data_formater($res);
        }else{
            return [];
        }
    }

    public function getOne($where,$field)
    {
        $res =  $this->where($where)->select($field)->first();
        if(!empty($res)){
            return $res;
        }else{
            return [];
        }
    }

    public function addOne($data)
    {
        return $this->insertGetId($data);
    }

    public function editOne($id,$data)
    {
        return $this->where('id',$id)->update($data);
    }

    /**
     * 删除
     * @param $id
     */
    public function del($ids)
    {
        return $this->whereIn('id',$ids)->delete();
    }
}